unit BaseRpt;

interface

uses
  Windows, SysUtils, Classes, Controls, StdCtrls, ExtCtrls, Forms,
  PoslovanjeSrv_TLB;

type
  TrptBase = class(TDataModule)
  private
    FSession: ISession;
    function GetReportPath: String;
    function GetMainForm: TForm;
    { Private declarations }
  protected
    FSQLFilter: string;
    function GetReportTitle: string; virtual;
    procedure Deinitialize; virtual;
    procedure Initialize; virtual;
  public
    constructor Create(AOwner: TComponent); overload; override;
    constructor Create(AOwner: TComponent; ASession: ISession; ASQLFilter: string); reintroduce; overload; virtual;
    procedure AfterConstruction; override;
    procedure BeforeDestruction; override;
    procedure Execute; virtual;
    property MainForm: TForm read GetMainForm;
    property ReportTitle: string read GetReportTitle;
    property ReportPath: String read GetReportPath;
    property Session: ISession read FSession write FSession;
  end;

  TrptBaseClass = class of TrptBase;

implementation

uses
  MainFrm, alActions;

{$R *.dfm}

{ TrptMain }

procedure TrptBase.AfterConstruction;
begin
  inherited;
  Screen.Cursor := crHourGlass;
  try
    Application.ProcessMessages;
    Initialize;
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TrptBase.BeforeDestruction;
begin
  Screen.Cursor := crHourGlass;
  try
    Application.ProcessMessages;
    Deinitialize;
  finally
    Screen.Cursor := crDefault;
  end;
  inherited;
end;

constructor TrptBase.Create(AOwner: TComponent);
begin
  inherited;

end;

constructor TrptBase.Create(AOwner: TComponent; ASession: ISession; ASQLFilter: string);
begin
  FSession := ASession;
  FSQLFilter := ASQLFilter;
  Create(AOwner);
end;

procedure TrptBase.Deinitialize;
begin

end;

procedure TrptBase.Execute;
begin
  
end;

function TrptBase.GetMainForm: TForm;
begin
  if Owner is TfrmMain then
    Result := TfrmMain(Owner)
  else
    Result := nil;
end;

function TrptBase.GetReportPath: String;
begin
  Result := ExtractFilePath(Application.ExeName) + 'Report\';
end;

function TrptBase.GetReportTitle: string;
begin
  if Owner is TReportPrint then
    Result := TReportPrint(Owner).Caption
  else
    Result := '';
end;

procedure TrptBase.Initialize;
begin

end;

end.
